import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
//创建线程
public class Easy_Use {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //定义任务
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int sum = 0;
                for (int i = 0; i <= 1000; i++) {
                    sum +=i;
                }
                return sum;
            }
        };
        FutureTask<Integer> futureTask = new FutureTask<>(callable); //futureTask未来的任务
        Thread t = new Thread(futureTask);
        t.start();
        System.out.println(futureTask.get());//获取callable返回结果 由于线程并发执行执行到主线程get时
        //t线程还未执行完导致get阻塞
    }
}
